<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of MoniController
 *
 * @author MinhQuan
 */
class MoniController {

    /**
     * Store model object
     * @var Moni
     */
    private $model;

    /**
     * Store view for the stream
     * @var MoniView
     */
    private $view;

    /**
     * 
     * @param type $model
     * @param type $view
     */
    public function __construct($model, $view) {
        $this->model = $model;
        $this->view = $view;
    }

    public function render() {
        //Need to edit
        //Param parser
        #remove the directory path we don't want      
		$userid=0;
        if(isset($_GET['df']))
        $datefrom = $_GET['df'];
        if(isset($_GET['dt']))
        $dateto = $_GET['dt'];
        if(isset($_GET['u']))
        $userid = $_GET['u'];   
        $url = $_SERVER['REQUEST_URI'];
        $test = explode("/",$url);
        $request = ltrim($url, '/');
        if (strpos($request, '?') != '') {
            $request = substr($request, 0, strpos($request, "?"));
        }
        #split the path by '/'
        $params = split("/", $request);
        $error = '';
        $signals = array();
        if ($params[2] == '') {
            $params[2] = $params[1];
            $params[1] = 'Overral';
        }
        if (strtoupper($params[2]) != 'VIEWPORT') {
           if($test['2'] != 'month' && $test['2'] != 'lastupdate' ){
            if(($datefrom ==NULL && $dateto == NULL && $userid == 0)){
                    $now = getdate(); 
                    $dayf = $now["mday"]-10;                
                    $datefrom = $now["year"]."-".$now["mon"]."-".$dayf;
                    $dateto = $now["year"]."-".$now["mon"]."-".$now["mday"];
                    $monis1 = Moni::loadMoni($datefrom,$dateto);
                }elseif(($datefrom !=NULL && $dateto != NULL ) ){
                    $monis1 = Moni::reloadMoni($datefrom, $dateto, $userid);
                }
            }else
            {
                $monis1 = Moni::monthU($userid);
            }
            
		}
        $this->view->model = $this->model;
        $this->view->monis1 = $monis1;
        $masterView = MasterView::getInstance();
        $masterView->moniView = $this->view;
        $masterView->params = $params;
    }	
}
?>
